package al.xc.task;

import al.xc.common.task.ITaskRunnable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogicTask implements ILogicTask {

    static final Logger logger = LoggerFactory.getLogger(LogicTask.class);

    /**
     * key
     */
    TaskKey key_;
    /**
     * 执行器
     */
    ITaskRunnable runnable_;

    public LogicTask(TaskKey key, ITaskRunnable runnable) {
        key_ = key;
        runnable_ = runnable;
    }

    /**
     * 执行体
     *
     * @return
     */
    @Override
    public void run() {
        if (null != runnable_) {
            try {
                runnable_.run();
            } catch (Exception ex){
                logger.warn("run task error", ex);
            }
        }
    }

    /**
     * 获取key
     *
     * @return
     */
    @Override
    public TaskKey getKey() {
        return key_;
    }
}
